package com.huige.wiki.controller;

import com.huige.wiki.req.DocQueryReq;
import com.huige.wiki.req.DocSaveReq;
import com.huige.wiki.resp.DocQueryResp;
import com.huige.wiki.resp.PageResp;
import com.huige.wiki.service.DocService;
import com.huige.wiki.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "文档相关接口")
@RequestMapping("/doc")
public class DocController {

    @Autowired
    DocService docService;

//    @GetMapping("/list")
//    @ApiOperation("查询文档")
//    public Result<PageResp<DocQueryResp>> list(@Validated DocQueryReq docQueryReq){
//        log.info("查询文档列表参数，{}",docQueryReq);
//        PageResp<DocQueryResp> pageResp = docService.list(docQueryReq);
//        return Result.success(pageResp);
//    }

    @GetMapping("/all/{ebookId}")
    @ApiOperation("查询指定电子书下的文档")
    public Result<List<DocQueryResp>> all(@PathVariable Long ebookId){
        List<DocQueryResp> list = docService.all(ebookId);
        return Result.success(list);
    }

    @PostMapping("/save")
    @ApiOperation("编辑文档（新增或修改）")
    public Result save(@RequestBody @Validated DocSaveReq docQueryReq){
        docService.save(docQueryReq);
        return Result.success();
    }

//    @PostMapping("/delete/{id}")
//    @ApiOperation("删除文档")
//    public Result delete(@PathVariable Long id){
//        docService.delete(id);
//        return Result.success();
//    }

    @DeleteMapping("/delete/{idsStr}")
    @ApiOperation("批量删除文档")
    public Result delete(@PathVariable String idsStr){
        docService.delete(idsStr);
        return Result.success();
    }

    @GetMapping("/find-content/{id}")
    @ApiOperation("查询指定文档内容")
    public Result<String> findContent(@PathVariable Long id){
        log.info("查询文档列表参数，{}",id);
        String content= docService.findContent(id);
        return Result.success(content);
    }

    @GetMapping("/vote/{id}")
    @ApiOperation("给指定文档点赞")
    public Result vote(@PathVariable Long id){
        docService.vote(id);
        return Result.success();
    }



}
